package com.yz.test;

public class DeckOfCards {
    public static void main(String[] args) {
        //定义花色  13张牌的大小
        String[] suits = {"红桃","黑桃","梅花","方块"};
        String[] ranks = {"3","4","5","6","7","8","9","10","J","Q","K","A","2"};

        //初始化纸牌，定义52张纸牌
        int[] cards = new int[52];
        for (int i = 0; i < cards.length; i++)
            cards[i] = i;
        //将牌的顺序打乱
        for (int i = 0; i < cards.length; i++) {
            int index = (int)(Math.random() * cards.length);
            int temp = cards[i];
            cards[i] = cards[index];
            cards[index] = temp;
        }

        //随机取出四张卡片
        for (int i = 0; i < 4; i++) {
            String suit = suits[cards[i] / 13];
            String rank = ranks[cards[i] % 13];

            System.out.println("卡牌数字是 "+cards[i]+":"+rank + "是" + suit+"花色！");
        }
    }
}
